const { defineConfig } = require('@vue/cli-service')
// 通过命令vue add axios 可以直接下载封装好了得axios
const Mock = require("mockjs")
const bodyParser = require("body-parser") // 解析post请求的
const Data = Mock.mock({
  "list|20":[{
     "title":"@ctitle",
     "score|1-10": 1,
      "name":"@cname",
      "cishu|100-900": 100,
      "id":"@id",
      "img":"@image(100x150,@color)"
  }]
})
module.exports = defineConfig({
  transpileDependencies: true,
  devServer:{
    onBeforeSetupMiddleware({app}){
        app.get("/list",(req,res)=>{ // 前端路由名不能和接口名字一样
          res.send(Data.list)
        })
        app.use(bodyParser.json()) // 写了这行以后就可以解析post请求
        app.post("/userlogin",(req,res)=>{  // req是请求体，res是响应体
           let {username,password} =req.body
           if (username == "123" && password == "123" ) {
             res.send({
               code:1,
               msg:"登陆成功"
             })
           } else {
             res.send({
               code:0,
               msg:"用户名或密码错误"
             })
           }
        })
    }
  }
})
